// store.js

import { createStore } from 'vuex';

import User from './User'; // Import the User class

const store = createStore({
    state: {
        currentUser: new User(null, '', '', '', '', '', ''),
    },
    mutations: {
        setCurrentUser(state, user) {
            state.currentUser = user
            // 将用户信息保存到 LocalStorage
            localStorage.setItem('currentUser', JSON.stringify(user));
            console.log(state.currentUser)
        },
        // 清除用户
        clearCurrentUser(state) {
            state.currentUser = null;
            // 从 LocalStorage 中移除用户信息
            localStorage.removeItem('currentUser');
        },
    },
});

export default store;
